﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Boiling.BizFacade;

namespace Boiling.Web
{
	public partial class Friend : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            string m_ask;
            string m_receive;
            string m_receive2;
            string m_showResult;

            if (Session.Contents["userID"] == null)
            {
                Response.Redirect("default.aspx");
            }

            m_ask = Request.QueryString["Ask"];
            m_receive = Request.QueryString["Receive"];
            m_receive2 = Request.QueryString["Receive2"];


            m_showResult = "";
            if (new UserSystem().GetUserIDByUserNo(m_ask) == (string)(Session.Contents["userID"]))
            {
                if (m_receive != null)
                {
                    if (new FriendManager().ApplyFriend(new UserSystem().GetUserIDByUserNo(m_ask), new UserSystem().GetUserIDByUserNo(m_receive)))
                    {
                        string temp = new UserSystem().GetUserIDByUserNo(m_receive);
                        c_UserInfo temp2 = new UserSystem().GetUserInfodatabyID(temp);
                        m_showResult = "您已经成功向" + temp2.userName + "发送了好友请求！";
                    }
                    else
                    {
                        m_showResult = "好友申请已经存在！";
                    }
                }
                if (m_receive2 != null)
                {
                    new FriendManager().AcceptFriendRequest(new UserSystem().GetUserIDByUserNo(m_ask), new UserSystem().GetUserIDByUserNo(m_receive2));
                    string temp = new UserSystem().GetUserIDByUserNo(m_receive2);
                    c_UserInfo temp2 = new UserSystem().GetUserInfodatabyID(temp);
                    m_showResult = "您已经成功接受" + temp2.userName + "的好友请求！";
                }
            }
            else
            {
                m_showResult = "非法操作！";
            }
            Session.Add("showResult", m_showResult);
		}
        public void LinkButton_Click(Object sender, EventArgs e)
        {

            if (Session.Contents["userID"] != null)
            {
                Session.Remove("userID");
            }
            Response.Redirect("Default.aspx");
        }
	}
}
